package com.hcy.app.api

import com.hcy.app.screen.cap.LinkDto
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import java.io.IOException

//sealed class ApiResult<out T> {
//    data class Success<T>(val data: T) : ApiResult<T>()
//    data class Error(val code: Int, val message: String) : ApiResult<Nothing>()
//}

data class BaseModel<T>(val stateCode:Int =0,val code: Int=0, val message: String="", val result: T?)
/**
 * Created Date: 2025/5/28
 * @author ChenRui
 * ClassDescription：处理Http状态码200，但是后端封装的基础数据类型中的code不为200的情况
 */
class BusinessException(msg: String) : IOException(msg)

//sealed class ApiResult<out T> {
//    data class Success<out T>(val data: T) : ApiResult<T>()
//    data class Error(
//        val code: Int,
//        val message: String?,
//        val errorBody: String?
//    ) : ApiResult<Nothing>()
//    object NetworkError : ApiResult<Nothing>()
//}
//data class BaseResponse<T>(
//    val success: Boolean,
//    val code: Int,
//    val message: String?,
//    val data: T?
//)



data class LoginAccount (val username: String,val password: String)
data class LoginSuccess(val username: String,val roles: List<String>,val token: String,val expires: String)
data class RefreshTokenDto(val token : String,val expires: String)
data class AddSessionForm(val linkId: String)


interface ApiService{

    @POST("sys/login")
    suspend fun login(@Body data:LoginAccount): BaseModel<LoginSuccess> // 登录

    @POST("sys/user/refreshToken")
    fun refreshToken(): BaseModel<RefreshTokenDto> //

    @GET("cap/link/list")
    suspend fun getLinkList(): BaseModel<List<LinkDto>>// 获取cap链接列表

    @POST("cap/session/add")
    suspend fun createCapSession(@Body data:AddSessionForm): BaseModel<String> // 创建cap会话,返回会话ID

}



